package com.tjetc.controller;


import com.tjetc.domain.User;
import com.tjetc.service.UserService;
import com.tjetc.util.JwtUtils;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (user)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;


    @GetMapping("selUserByPhone")
    public Result selUserByPhone(@RequestParam("phone") String phone) {
        return userService.selUserByPhone(phone);
    }

    @GetMapping("login")
    public Result login(@RequestParam("phone") String phone) {
        return userService.login(phone);
    }
    @GetMapping("updateSendMsg")
    public Result updateSendMsg(@RequestParam("phone") String phone) {
        return userService.updateSendMsg(phone);
    }
    @GetMapping("updatePhone")
    public Result updatePhone(@RequestParam("oldPhone") String oldPhone, @RequestParam("newPhone") String newPhone, @RequestParam("code") String code) {
        return userService.updatePhone(oldPhone, newPhone, code);
    }

    @GetMapping("register")
    public Result register(@RequestParam("phone") String phone) {
        return userService.register(phone);
    }

    @GetMapping("registerSave")
    public Result registerSave(@RequestParam("phone") String phone) {
        return userService.registerSave(phone);
    }

    @GetMapping("verifyCode")
    public Result verifyCode(@RequestParam("code") String code, @RequestParam("phone") String phone) {
        return userService.verifyCode(phone, code);
    }

    @PostMapping("shiming")
    public Result shiming(@RequestBody User user) {
        return userService.shiming(user);
    }

    @GetMapping("test")
    public Result test(@RequestHeader("token") String token) {
        System.out.println(token);
        return Result.ok();
    }

    @GetMapping("/checkToken")
    public boolean checkToken(@RequestHeader("token") String token) {
        return JwtUtils.checkToken(token);
    }

    @GetMapping("getPatients")
    public Result getPatients(@RequestParam("phone") String phone) {
        return userService.getPatients(phone);
    }

    @GetMapping("SelphoneById")
    public Result SelphoneById(@RequestParam("id") Integer id) {
        return userService.SelphoneById(id);
    }

    @GetMapping("UpdatephoneById")
    public Result UpdatephoneById(
            @RequestParam("id") Integer id,
            @RequestParam("phone") String phone
    ) {
        return userService.UpdatephoneById(id, phone);
    }

    @GetMapping("findAllPatients")
    public Result findAllPatients(
            @RequestParam("phone") String phone,
            @RequestParam("input") String input
    ) {
        return userService.findAllPatients(phone, input);
    }

    @GetMapping("findUserIdByPhone")
    public Result findUserByPhone(
            @RequestParam("phone") String phone
    ) {
        return userService.findUserByPhone(phone);
    }

   
}
